import pyautogui
import uiautomation
class IndexPage():
        his = uiautomation.WindowControl(searchDepth=1, Name='科玛奇医院信息管理系统')  # 锁定窗口
        his.SetFocus()
        #搜索框
        shoushuokuang = his.CustomControl(ClassName='TitleBar').EditControl(AutomationId='SearchTextBox', ClassName='TextBox')
        #设置按钮
        shezhi = his.ButtonControl(AutomationId='SettingButton', ClassName='Button')
        #选择药房
        xuanzeyaofang = his.WindowControl(ClassName='Popup').CustomControl(ClassName='ButtonBar',foundIndex=3)
        #选择工作科室
        xuanzegongzuokeshi =  his.WindowControl(ClassName='Popup').CustomControl(ClassName='ButtonBar',foundIndex=4)
        #选择工作病区
        xuanzegongzuobingqu = his.WindowControl(ClassName='Popup').CustomControl(ClassName='ButtonBar',foundIndex=5)
        #打印设置
        dayinshezhi = his.WindowControl(ClassName='Popup').CustomControl(ClassName='ButtonBar',foundIndex=12)
        #服务登记设置
        fuwudenjishezhi = his.WindowControl(ClassName='Popup').CustomControl(ClassName='ButtonBar',foundIndex=13)
        #手术管理设置
        shoushuguanlishezhi = his.WindowControl(ClassName='Popup').CustomControl(ClassName='ButtonBar',foundIndex=14)
        #点击选择药房
        def choose_yf(self):
                self.click_sz_btn()
                self.xuanzeyaofang.Click()
        #点击选择工作科室
        def choose_gzks(self):
                self.click_sz_btn()
                self.xuanzegongzuokeshi.Click()
        #点击选择工作病区
        def choose_gzbq(self):
                self.click_sz_btn()
                self.xuanzegongzuobingqu.Click()
        #点击选择打印设置
        def choose_dysz(self):
                self.click_sz_btn()
                self.dayinshezhi.Click()
        #点击选择打手术管理设置
        def choose_ssgl(self):
                self.click_sz_btn()
                self.shoushuguanlishezhi.Click()
        #点击服务登记设置
        def choose_fwdjsz(self):
                self.click_sz_btn()
                self.fuwudenjishezhi.Click()





        #弹窗
        tanchuang = his.WindowControl(ClassName='Window')
        #最大化窗口
        def max_window(self):
                self.tanchuang.Refind()
                self.tanchuang.Maximize()
        #关闭窗口
        def close_window(self):
                self.tanchuang.Refind()
                self.tanchuang.GetWindowPattern().Close()
#药房设置
        xuanzeyaofang1 = tanchuang.ComboBoxControl(ClassName='ComboBox',foundIndex=1)
        xiyao1 = his.WindowControl(ClassName='Popup').ListItemControl(ClassName='ListBoxItem',Name='药房(4007)')
        def choose_xzyf(self):
                self.xuanzeyaofang1.Click()
                self.xiyao1.Click()
        kuang2 =tanchuang.CustomControl(AutomationId='CBCtrl1').ComboBoxControl(AutomationId='cob_Box',ClassName='ComboBox')
        bianjikuang2 = tanchuang.EditControl(AutomationId='txb_EditBox')
        xiyao = his.ListItemControl(ClassName='ListBoxItem',Name='System.Data.DataRowView')
        def choose_xcyzxks(self,YF_name):
                uiautomation.Click(1200,502,waitTime=1)
                YF  = self.bianjikuang2.GetValuePattern().Value
                yfmc = self.kuang2.GetChildren()
                if YF_name in YF:
                        uiautomation.Click(1300, 502, waitTime=1)
                else:
                        for i in yfmc:
                                if i.GetFirstChildControl().Name in YF_name:
                                        i.GetFirstChildControl().GetFirstChildControl().Click()
                uiautomation.Click(1300, 502, waitTime=1)

        kuang3 =tanchuang.CustomControl(AutomationId='CBCtrl2').ComboBoxControl(AutomationId='cob_Box',ClassName='ComboBox')
        bianjikuang3 = tanchuang.CustomControl(AutomationId='CBCtrl2').EditControl(AutomationId='txb_EditBox')
        def choose_zcyzxks(self,YF_name):
                uiautomation.Click(1200, 557, waitTime=1)
                YF = self.bianjikuang3.GetValuePattern().Value
                yfmc = self.kuang3.GetChildren()
                if YF_name in YF:
                        uiautomation.Click(1300, 502, waitTime=1)
                else:
                        for i in yfmc:
                                if i.GetFirstChildControl().Name in YF_name:
                                        print(i.GetFirstChildControl().Name)
                                        i.GetFirstChildControl().GetFirstChildControl().Click()
                uiautomation.Click(1300, 502, waitTime=1)
        queding = tanchuang.ButtonControl(ClassName='Button',Name='确定')
        def click_qd_btn(self):
                self.queding.Refind()
                self.queding.Click()
        def yfsz(self,YF_name1,YF_name2):
                self.choose_yf()
                self.max_window()
                self.choose_xzyf()
                self.choose_xcyzxks(YF_name1)
                self.choose_zcyzxks(YF_name2)
                self.click_qd_btn()

#病区设置
        bingquxuanze = tanchuang.GroupControl(ClassName='GroupBox',Name='病区')
        zhuyuanqu = his.ListItemControl(ClassName='ListBoxItem',Name='住院区(1007)')
        xuanze = tanchuang.ButtonControl(ClassName='Button',Name='选择')
        #选择病区
        def choose_bq(self):
                self.bingquxuanze.Click()
                self.zhuyuanqu.Click()
        #点击选择
        def click_xz_btn(self):
                self.xuanze.Refind()
                self.xuanze.Click()

        #工作病区设置
        def gzbqsz(self):
                self.choose_gzbq()
                self.max_window()
                self.choose_bq()
                self.click_xz_btn()

#科室设置
        keshixuanze = tanchuang.GroupControl(ClassName='GroupBox',Name='科室')
        neike1 = his.ListItemControl(ClassName='ListBoxItem',Name='内科1(4002)')
        #选择科室
        def choose_ks(self):
                self.keshixuanze.Click()
                self.neike1.Click()

        #工作科室设置
        def gzkssz(self):
                self.choose_gzks()
                self.max_window()
                self.choose_ks()
                self.click_xz_btn()

#打印设置
        quanjudayinshezhi = his.GroupControl(ClassName='GroupBox',Name='全局打印机一键设置').ComboBoxControl(AutomationId='QJPrinter', ClassName='ComboBox')
        GS1 = quanjudayinshezhi.ListControl(ClassName='ListBoxItem',Name='Microsoft Print to PDF')
        baocun = tanchuang.ButtonControl(ClassName='Button',Name='保存')
        def click_bc_btn(self):
                self.tanchuang.Refind()
                self.baocun.Refind()
                self.baocun.Click()
        def click_qjdy(self):
                self.quanjudayinshezhi.Click()
                self.quanjudayinshezhi.GetFirstChildControl().Click()
        def dyjsz(self):
                self.choose_dysz()
                self.max_window()
                uiautomation.Click(960,519)
                pyautogui.scroll(clicks=-500)
                self.click_qjdy()
                self.click_bc_btn()

#服务登记设置
        fuwudenjichuangkou = his.WindowControl(AutomationId='fwdjszUI', ClassName='Window',Name='服务登记设置')
        #普通医生
        ZHIDINGYI2 = fuwudenjichuangkou.CustomControl(AutomationId='fwdj', ClassName='FWDJSettingView')
        putongyisheng_guahaoleibie = ZHIDINGYI2.EditControl(AutomationId='PART_TextBox', ClassName='TextBox',foundIndex=1)
        putongyisheng_keshi =  ZHIDINGYI2.EditControl(AutomationId='PART_TextBox', ClassName='TextBox',foundIndex=2)
        putongyisheng_feibie =  ZHIDINGYI2.EditControl(AutomationId='PART_TextBox', ClassName='TextBox',foundIndex=3)
        putongyisheng_menzhenleixing = ZHIDINGYI2.ComboBoxControl(ClassName='ComboBox',foundIndex=1)

                #选择普通医生挂号类别
        def choose_ptys_ghlb(self,ghlb):
                self.putongyisheng_guahaoleibie.Click()
                self.putongyisheng_guahaoleibie.SendKeys(ghlb)
                pyautogui.press('enter')
                #选择普通医生科室
        def choose_ptys_ks(self,ks):
                self.putongyisheng_keshi.Click()
                self.putongyisheng_keshi.SendKeys(ks)
                pyautogui.press('enter')
                #选择普通医生费别
        def choose_ptys_fb(self,fb):
                self.putongyisheng_feibie.Click()
                self.putongyisheng_feibie.SendKeys(fb)
                pyautogui.press('enter')
                #选择普通医生门诊类型
        def choose_ptys_mzlx(self,mzlx):
                self.putongyisheng_menzhenleixing.Click()
                self.putongyisheng_menzhenleixing.SendKeys(mzlx)
                pyautogui.press('enter')

        #急诊医生
        ZHIDINGYI3  = fuwudenjichuangkou.CustomControl(AutomationId='yjz', ClassName='FWDJSettingView')
        jizhenyishen_guahaoleibie = ZHIDINGYI3.EditControl(AutomationId='PART_TextBox', ClassName='TextBox',foundIndex=1)
        jizhenyishen_keshi = ZHIDINGYI3.EditControl(AutomationId='PART_TextBox', ClassName='TextBox', foundIndex=2)
        jizhenyishen_feibie = ZHIDINGYI3.EditControl(AutomationId='PART_TextBox', ClassName='TextBox', foundIndex=3)
        jizhenyishen_menzhenleixing = ZHIDINGYI3.ComboBoxControl(ClassName='ComboBox', foundIndex=1)
                # 选择急诊医生挂号类别
        def choose_jzys_ghlb(self, ghlb):
                self.jizhenyishen_guahaoleibie.Click()
                self.jizhenyishen_guahaoleibie.SendKeys(ghlb)
                pyautogui.press('enter')
                # 选择急诊医生科室
        def choose_jzys_ks(self, ks):
                self.jizhenyishen_keshi.Click()
                self.jizhenyishen_keshi.SendKeys(ks)
                pyautogui.press('enter')
                # 选择急诊医生费别
        def choose_jzys_fb(self, fb):
                self.jizhenyishen_feibie.Click()
                self.jizhenyishen_feibie.SendKeys(fb)
                pyautogui.press('enter')
                # 选择急诊医生门诊类型
        def choose_jzys_mzlx(self, mzlx):
                self.jizhenyishen_menzhenleixing.Click()
                self.jizhenyishen_menzhenleixing.SendKeys(mzlx)
                pyautogui.press('enter')
        # 服务登记设置
        def fwdjsz(self,ghlb,ks,fb,mzlx,ghlb1,ks1,fb1,mzlx1):
                self.choose_fwdjsz()
                self.choose_ptys_ghlb(ghlb)
                self.choose_ptys_ks(ks)
                self.choose_ptys_fb(fb)
                self.choose_ptys_mzlx(mzlx)
                self.choose_jzys_ghlb(ghlb1)
                self.choose_jzys_ks(ks1)
                self.choose_jzys_fb(fb1)
                self.choose_jzys_mzlx(mzlx1)
                self.click_bc_btn()
                self.close_window()


#手术管理设置
        gongzuoshoushushi = tanchuang.EditControl(AutomationId='PART_TextBox',ClassName='TextBox',foundIndex=1)
        yaofang = tanchuang.EditControl(AutomationId='PART_TextBox',ClassName='TextBox',foundIndex=2)
        cailiaofang = tanchuang.EditControl(AutomationId='PART_TextBox',ClassName='TextBox',foundIndex=3)
        shoushupaibandayingji = tanchuang.ComboBoxControl(ClassName='ComboBox')
        #选择工作手术室
        def choose_gzsss(self,SSS):
                self.gongzuoshoushushi.Click()
                self.gongzuoshoushushi.SendKeys(SSS)
        #选择药房
        def choose_ssyf(self,YF):
                self.yaofang.Click()
                self.yaofang.SendKeys(YF)
        #选择材料房
        def choose_ssclf(self,CLF):
                self.cailiaofang.Click()
                self.cailiaofang.SendKeys(CLF)
        #手术打印设置
        def ssdyj(self):
                self.shoushupaibandayingji.Click()
                self.shoushupaibandayingji.GetFirstChildControl().Click()
        #手术管理参数设置
        def ssglcssz(self,SSS,YF,CLF):
                self.choose_ssgl()
                self.max_window()
                self.choose_gzsss(SSS)
                self.choose_ssyf(YF)
                self.choose_ssclf(CLF)
                self.ssdyj()
                self.click_bc_btn()
                self.close_window()


        #第一个列表
        l1 = his.ListControl(AutomationId='listBox', ClassName='ListBox').ButtonControl(ClassName='Button',foundIndex=1)
        #第一个数据
        r1 = his.ListControl(AutomationId='MenuSub', ClassName='ListBox').ButtonControl(ClassName='Button',foundIndex=1)
        #万能进入页面方法
        def jrym_no1(self,ymmc):
                self.shoushuokuang.Click()
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.hotkey('back')
                self.shoushuokuang.SendKeys(ymmc)
                self.r1.Refind()
                self.r1.Click()

        #点击设置
        def click_sz_btn(self):
                self.shezhi.Refind()
                self.shezhi.Click()
                pyautogui.press('enter')

#选项卡
        xuanxiangka = his.TabControl()
        def close_all_xxk(self):
                all=self.xuanxiangka.GetChildren()
                for i in range(len(all)):
                        self.xuanxiangka.GetFirstChildControl().GetFirstChildControl().ButtonControl().DoubleClick()